import java.util.Scanner;

/**
 * 提示用户输入年月日信息，判断这一天是这一年中的第几天并打印。
 * @author cyt
 * @date 2020/6/6
 */
public class FirstQuestion {

    /**
     * return the days of month according to year
     * @param year
     * @param month
     * @return int
     */
    public static int daysOfMonth(int year, int month){
        switch (month){
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                return 31;
            case 2:
                //judge whether the year is leap year or not
                if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)){
                    return 29;
                }else {
                    return 28;
                }
            case 4:
            case 6:
            case 9:
            case 11:
                return 30;
            default:
                return 0;
        }
    }

    /**
     * calculate the days in the year
     * @param year
     * @param month
     * @param date
     * @return int
     */
    public static int daysCalculcation(int year, int month, int date){
        int days = 0;
        for(int i = 1; i <= month - 1; i++){
            days += daysOfMonth(year, i);
            System.out.println(days);
        }
        days += date;
        return days;
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println(daysOfMonth(1,2));
        System.out.println("请根据提示输入年月日信息！");
        int year;
        int month;
        int date;
        while (true){
            System.out.println("请输入年份：");
            year = sc.nextInt();
            if(year > 0){
                break;
            }else {
                System.out.println("输入有误，请输入正确的年份");
            }
        }
        while (true){
            System.out.println("请输入月份：");
            month = sc.nextInt();
            if(month > 0 && month <= 12){
                break;
            }else {
                System.out.println("输入有误，请输入正确的月份");
            }
        }

        while (true){
            System.out.println("请输入日期: ");
            date = sc.nextInt();
            if (date > 0 && date <= daysOfMonth(year,month)){
                break;
            }else {
                System.out.println("输入有误，请输入正确的日期");
            }
        }


        int days = daysCalculcation(year,month,date);

        System.out.printf("这一天是%d年的第%d天",year,days);
    }
}
